<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>RobotComm: RobotComm库接口文档</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">RobotComm
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.17 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">RobotComm库接口文档 </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="autotoc_md1"></a>
一、简介</h1>
<p>本文档由 Doxygen 自动生成，罗列了通讯相关的公共接口函数，通讯管理相关的类，以及各类简介。</p>
<h1><a class="anchor" id="autotoc_md2"></a>
二、通讯管理类关系图</h1>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20201014194011601.png" alt="image-20201014194011601" class="inline"/></p>
<h1><a class="anchor" id="autotoc_md3"></a>
三、用法简介</h1>
<p>所有通讯配置函数生效的前提，必须让PLC线程周期调用对应的loop函数。</p>
<h2><a class="anchor" id="autotoc_md4"></a>
1、ModbusTCP客户端</h2>
<p>参数配置如下，受通讯报文长度限制，ModbusTCP最大通讯字限制为120。</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">typedef struct</div>
<div class="line">{</div>
<div class="line">    bool b_enable;                      ///&lt;通讯启用使能</div>
<div class="line">    bool b_read;                        ///&lt;通讯周期读使能</div>
<div class="line">    bool b_write;                       ///&lt;通讯周期写使能</div>
<div class="line">    char ip[20];                        ///&lt;IP地址</div>
<div class="line">    unsigned short port;                ///&lt;端口</div>
<div class="line">    unsigned short station_id;          ///&lt;站地址</div>
<div class="line">    unsigned short read_start_adress;   ///&lt;读起始地址</div>
<div class="line">    unsigned short read_data_len;       ///&lt;读数据长度</div>
<div class="line">    unsigned short write_start_adress;  ///&lt;写起始地址</div>
<div class="line">    unsigned short write_data_len;      ///&lt;写数据长度</div>
<div class="line">    unsigned short *p_di_data;          ///&lt;输入数据地址</div>
<div class="line">    unsigned short *p_do_data;          ///&lt;输出数据地址</div>
<div class="line">    unsigned short time_out;            ///&lt;超时时间,单位毫秒</div>
<div class="line">}SModbusTcpClientInfo;</div>
</div><!-- fragment --><p>通过接口函数 void setModbusTcpClientInfo(SModbusTcpClientInfo *info) 配置通讯参数，开启和关闭通讯。</p>
<p>使用示例如下：</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">//第一次配置通讯参数并开启通讯</div>
<div class="line">SModbusTcpClientInfo info;</div>
<div class="line">info.b_read = true;         //通讯读使能打开</div>
<div class="line">info.b_write = true;        //通讯写使能打开</div>
<div class="line">//IP地址赋值</div>
<div class="line">strcpy(info.ip,string(&quot;192.168.0.10&quot;).c_str());</div>
<div class="line">info.port = 502;            //设置端口</div>
<div class="line">//其他参数配置省略...</div>
<div class="line">info.b_enable = true;       //通讯使能开启</div>
<div class="line">setModbusTcpClientInfo(&amp;info);</div>
<div class="line"> </div>
<div class="line">//关闭通讯</div>
<div class="line">SModbusTcpClientInfo info = *getModbusTcpClientInfo();</div>
<div class="line">info.b_enable = false;</div>
<div class="line">setModbusTcpClientInfo(&amp;info);</div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md5"></a>
2、ModbusTCP服务端</h2>
<p>参数配置如下，受系统XY变量限制，服务端的总数据量为200字，一半给输入X，一半给输出Y。</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">typedef struct</div>
<div class="line">{</div>
<div class="line">    bool b_enable;                  ///&lt;使能</div>
<div class="line">    char ip[20];                    ///&lt;IP地址</div>
<div class="line">    unsigned short port;            ///&lt;端口</div>
<div class="line">    unsigned short *p_di_data;      ///&lt;输入数据地址</div>
<div class="line">    unsigned short *p_do_data;      ///&lt;输出数据地址</div>
<div class="line">    unsigned short time_out;        ///&lt;超时时间</div>
<div class="line">}SModbusTcpServerInfo;</div>
</div><!-- fragment --><p>服务端配置用法类同客户端。</p>
<p>和客户端不同的是，服务端通讯可以允许多个客户端连接，通过接口函数获取所有连接。</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">vector&lt;STcpConnectClientInfo&gt; getModbusTcpServerConnectList();</div>
</div><!-- fragment --><p>连接客户端信息数据：</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">typedef struct</div>
<div class="line">{</div>
<div class="line">    std::string ip;                 ///&lt;IP地址</div>
<div class="line">    unsigned short port;            ///&lt;端口</div>
<div class="line">    unsigned long last_comm_time;   ///&lt;上一次数据交互时间(ms)</div>
<div class="line">    char * connect_;                ///&lt;连接connect指针</div>
<div class="line">}STcpConnectClientInfo;</div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md6"></a>
3、ModbusTCP视觉客户端</h2>
<p>参数配置同ModbusTCP通用客户端，使用方法也类同。视觉客户端比通用客户端多一种辅助通讯命令。</p>
<p>在周期读写的基础上，添加辅助接口，可实现一次额外数据的读或者写。配置如下所示：</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">typedef struct</div>
<div class="line">{</div>
<div class="line">    bool read_enb;                  ///&lt;true为读，false为写</div>
<div class="line">    unsigned short start_adress;    ///&lt;读/写 起始地址</div>
<div class="line">    unsigned short data_len;        ///&lt;读/写 数据长度</div>
<div class="line">    unsigned short *p_data;         ///&lt;数据指针</div>
<div class="line">    bool *is_finish;                ///&lt;通讯完成状态</div>
<div class="line">}SModbusTcpClientCmdEx;</div>
</div><!-- fragment --><p>用法示例如下：</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">unsigned short data = 0xFF;     //发送的数据</div>
<div class="line">bool is_finish = false;         //辅助通讯的结果状态</div>
<div class="line">SModbusTcpClientCmdEx cmd;</div>
<div class="line">cmd.read_enb = false;           //写数据</div>
<div class="line">cmd.start_adress = 1;</div>
<div class="line">cmd.data_len = 1;</div>
<div class="line">cmd.is_finish = &amp;is_finish;</div>
<div class="line">cmd.p_data = &amp;data;</div>
<div class="line">if (addModbusTcpClientCmdEx(&amp;cmd) == true)  //发送辅助通讯指令</div>
<div class="line">{</div>
<div class="line">    while(1)</div>
<div class="line">    {</div>
<div class="line">        if (is_finish == true)              //循环判断通讯结果</div>
<div class="line">        {</div>
<div class="line">            break;</div>
<div class="line">        }</div>
<div class="line">        Sleep(10);   </div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md7"></a>
4、gibbon标定通讯管理类</h2>
<p>gibbon标定通讯专用于使用Gibbon标定机器人。机器人作为TCP客户端，标定设备作为TCP服务端。IP地址固定，端口固定，通讯数据格式固定。</p>
<h2><a class="anchor" id="autotoc_md8"></a>
5、远程TCP通讯管理类</h2>
<p>远程TCP协议，机器人只能做服务端，被动相应客户机的通讯请求。配置信息如下所示：</p>
<div class="fragment"><div class="line"> {c++}</div>
<div class="line">typedef struct</div>
<div class="line">{</div>
<div class="line">    bool b_enable;                  ///&lt;使能</div>
<div class="line">    char ip[20];                    ///&lt;IP地址</div>
<div class="line">    unsigned short port;            ///&lt;端口</div>
<div class="line">}SUserTcpServerInfo;</div>
</div><!-- fragment --><p>通讯协议内容详见开发手册。 </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
